<template>
  <div class="bigScreen">
    <div class="banner">
      <div class="show1">SanTanNew购卡平台</div>
      <div class="show2">简单、快捷、全面的一站式购卡平台</div>
    </div>
    <div class="feature" style="margin-top: 1em">
      <div class="feature_item_2" @click="goToResult">
        <div class="centerBox">
          <div id="qrCode" ref="qrCodeDiv"></div>
          <div class="tip">请使用微信扫描二维码付款</div>
          <div class="gotoPay" v-if="!isPc" @click="gotoPay">
            手机长按识别不了验证码？点我直接跳转
          </div>
          <div class="tipRed" v-if="!isPc">
            付款成功后请到'首页'查询订单信息
          </div>
          <div class="tipRed" v-if="isPc">付款成功后请在该页面稍等</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import QRCode from "qrcodejs2";
import { IsPC, beginSearchPayStatus } from "../utils/pay";
import bigScreen from "@/api/bigScreen";
export default {
  data() {
    return {
      writePayInfo: false,
      isPaying: false,
      form: {
        number: 1,
        phone: "",
      },
    };
  },
  data() {
    return {
      imageUrl: "",
      isPc: IsPC(),
      form: {},
    };
  },
  mounted: function () {
    if (
      (this.$route.query &&
        this.$route.query.phone &&
        this.$route.query.cnt > 0) ||
      this.$route.query.payType == "ajPay"
    ) {
      this.form = this.$route.query;
      this.$nextTick(function () {
        this.bindQRCode();
      });
    } else {
      this.$router.push({
        name: "choseObject",
      });
    }
  },
  methods: {
    async bindQRCode() {
      let res = {};
      localStorage.setItem("payType", this.$route.query.payType);
      if (this.$route.query.payType == "ajPay") {
        if (this.$route.query.orderNo) {
          res = await bigScreen.getOrderScriptUrl({
            platformId: this.$route.query.orderNo,
          });
          localStorage.setItem("payType", "ajPay");
        } else {
          return;
        }
      } else {
        res = await bigScreen.getUrl({
          phone:this.form.phone,
          amount:this.form.amount,
          type:this.form.type,
          goodId:this.form.id,
          payway:'1'
        });
      }
      this.imageUrl = res.jumpUrl;
      localStorage.setItem("UUID", res.uuid);

      new QRCode(this.$refs.qrCodeDiv, {
        text: res.jumpUrl,
        width: 200,
        height: 200,
        colorDark: "#333333", //二维码颜色
        colorLight: "#ffffff", //二维码背景色
        correctLevel: QRCode.CorrectLevel.L, //容错率，L/M/H
      });
      beginSearchPayStatus();
    },
    gotoPay() {
      if (this.imageUrl && localStorage.getItem("UUID")) {
        window.location.href = this.imageUrl;
        // window.open(this.imageUrl)
      }
    },
    goToResult() {
      this.$router.push({
        name: "payResult",
        query:{
					payType:localStorage.getItem('payType')
				}
      });
    },
  },
  beforeDestroy() {},
};
</script>

<style lang="scss" scoped>
.bigScreen {
  width: 90%;
  text-align: center;
  padding-top: 0em;
  margin: 0 auto;
  background-color: #f5f7fb !important;
  .banner {
    background-color: #4aac94;
    padding-top: 3em;
    padding-bottom: 3em;
    .show1 {
      margin: 0;
      font-weight: 400;
      color: #fff;
      font-size: 3rem;
    }
    .show2 {
      margin-top: 1.2em;
      margin-bottom: 0;
      font-weight: 400;
      color: #fff;
      font-size: 1.2rem;
    }
    .show3 {
      font-weight: 400;
      margin-top: 0.8em;
      color: #fff;
      font-size: 1.2rem;
      margin-bottom: 0;
    }
  }
  .feature {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-font-smoothing: antialiased;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.42857143;
    color: #333;
    text-align: center;
    box-sizing: border-box;
    margin-top: 1em;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    .feature_item {
      cursor: pointer;
      vertical-align: top;
      display: inline-block;
      width: 22em;
      margin: 1em 1em;
      background-color: #fff;
      padding: 0.5em 2.5em;
      padding-bottom: 2em;
      box-shadow: 0 3px 3px 0 rgb(0 0 0 / 5%);
    }
    .feature_item_2 {
      cursor: pointer;
      vertical-align: top;
      display: inline-block;
      margin: 1em 1em;
      background-color: #fff;
      padding: 0.5em 2.5em;
      padding-bottom: 2em;
      padding-top: 2em;
      box-shadow: 0 3px 3px 0 rgb(0 0 0 / 5%);
      display: flex;
      flex-direction: column;
      justify-content: center;
      margin-top: 25rpx;

      .centerBox {
        display: flex;
        flex-direction: column;
        justify-content: center;
        margin-top: 25px;

        #qrCode {
          text-align: center;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        .tip {
          text-align: center;
          margin-top: 30px;
          font-size: 1rem;
        }

        .tipRed {
          text-align: center;
          margin-top: 10px;
          color: red;
          font-size: 1rem;
        }
      }

      .page-title {
        display: inline-block;
        position: relative;
        padding-right: 25px;
        padding-bottom: 15px;
        color: #a788e7;
        font-size: 1.4em;
        text-align: left;
      }
      .page-title-wx {
        display: inline-block;
        position: relative;
        padding-right: 25px;
        padding-bottom: 15px;
        color: #67c23a;
        font-size: 1.4em;
        text-align: left;
      }
      .page-item {
        font-size: 1em;
        color: grey;
        text-align: left;
      }
    }
    .item_iconfont_1 {
      width: 10rem;
      height: 10rem;
      margin-top: 1.5em;
    }

    .item_iconfont_2 {
      width: 3rem;
      height: 3rem;
      margin-top: 1.5em;
    }
    .item_iconfont_3 {
      width: 3rem;
      height: 3rem;
    }
    .item_iconfont {
      width: 5rem;
      height: 5rem;
      margin-top: 1.5em;
    }
    .title {
      margin-top: 0.6em;
      margin-bottom: 0.6em;
      font-size: 2.5rem;
      width: 100%;
    }
    .feature_item .content {
      line-height: 200%;
      font-size: 1rem;
      color: #444;
    }
  }
  a {
    color: #4aac94;
    text-decoration: none;
  }
}
h2 {
  display: block;
  font-size: 1.5em;
  margin-block-start: 0.83em;
  margin-block-end: 0.83em;
  margin-inline-start: 0px;
  margin-inline-end: 0px;
  font-weight: bold;
}
.titleSpecial {
  margin-top: 1.6em;
  margin-bottom: 0.6em;
  font-size: 2.5rem;
  width: 100%;
}
.ddje {
  width: 100%;
  text-align: left;
  color: red;
}
.payBox {
  justify-content: center;
  display: flex;
  align-items: center;
  button {
    display: flex;
    align-items: center;
  }
}
</style>